﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EWineShop.Service.Model;
using EWineShop.Service.Contracts;
using EWineShop.Service;

namespace EWineShop.AdminSite.Controllers
{
    public class FoodUnitController : Controller
    {

        IFoodUnitService IFoodUnit = new FoodUnitService();

        IIDCreaterService IIDCreater = new IDCreaterService();

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Save(FormCollection collection)
        {

            FoodUnitModel model = new FoodUnitModel()
            {

                FoodUnitID = IIDCreater.GetNewID("FoodUnitID", "菜品属性ID", 1000),
                Name = collection["txtName"],
                Remark = "",
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Parse("1900-01-01")
            };

            IFoodUnit.AddFoodUnit(model);

            return null;
        }

        public ActionResult Update(FormCollection collection)
        {
            FoodUnitModel model = new FoodUnitModel()
            {
                FoodUnitID = Int64.Parse(collection["HDFoodUnitID"]),
                Name = collection["txtName"],
                Remark = "",
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now
            };

            IFoodUnit.UpdateByFoodUnitID(model);

            return null;

        }

        public ActionResult Delete(Int64 id)
        {
            IFoodUnit.DeleteByFoodUnitID(id);
            return null;
        }
    }
}
